package com.team2.s3hrjyxm.qxglcontroller;

import com.team2.s3hrjyxm.QxglService.LoginService;
import com.team2.s3hrjyxm.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class LoginController {
    @Autowired
    LoginService service;

            @PostMapping("login")
            public String Login(Users u, Map map, HttpSession session){
                u=service.login(u);
                if(u!=null){
                  session.setAttribute("user",u.getU_true_name());
                  session.setAttribute("users",u);
                  return "/page/index.html";
                   }else{
                    map.put("users","用户名或密码错误" );
                  return "login.html";
                  }
             }

         @RequestMapping("log")
        public String log(){
           return "login.html";
    }
         @GetMapping("top")
        public String top(){
         return "/page/top.html";
          }
         @GetMapping("left")
        public String left(){

        return "/page/left.html";
    }
         @GetMapping("main")
        public String main(){
        return "/page/main.html";
    }

         @GetMapping("session")
        public String  Sessions(HttpSession session){
                 session.invalidate();
                 return "login.html";
    }
}
